package com.kaibes.module.file.local.api;

import java.math.BigInteger;
import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.kaibes.core.base.annotation.Description;
import com.kaibes.module.file.local.db.FileMark;
import com.kaibes.module.file.local.db.FileMarkService;
import com.kaibes.web.api.ApiLink;
import com.kaibes.web.api.ResponseApi;
import com.kaibes.web.response.ResponseFactory;

@RestController
@RequestMapping("/files/marks")
public class FileMarkApi extends ResponseApi<FileMark, FileMarkService> {

    @ApiLink("删除文件标记，根据id")
    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody @Description("文件标记ID数组") List<BigInteger> ids) {
        return super.deleteByIds(ids, "删除文件标记成功", "删除文件标记失败");
    }
    
    @ApiLink("删除文件标记，根据id")
    @DeleteMapping("/{id:\\d+}")
    public ResponseEntity<Object> delete(@PathVariable @Description("文件标记ID") BigInteger id) {
        return super.deleteById(id, "删除文件标记成功", "删除文件标记失败");
    }
    
    @ApiLink(value = "用户删除自己的文件，根据id", validated = false)
    @DeleteMapping("/self")
    public ResponseEntity<Object> deleteByUser(@RequestAttribute Integer userId, @RequestBody @Description("文件标记ID数组") List<BigInteger> ids) {
        return ResponseFactory.delete(service.removeByIdsAndUserId(ids, userId), "删除文件成功", "删除文件失败");
    }
    
    @ApiLink(value = "用户删除自己的文件，根据id", validated = false)
    @DeleteMapping("/self/{id:\\d+}")
    public ResponseEntity<Object> deleteByUser(@RequestAttribute Integer userId, @PathVariable @Description("文件标记ID") BigInteger id) {
    	return ResponseFactory.delete(service.removeByIdAndUserId(id, userId), "删除文件成功", "删除文件失败");
    }
    
}
